package bcxd.firstline.supplier.machining;

import java.sql.Connection;
import java.util.Map;

import jt.classic.system.context.ISystemContext;
import jt.classic.system.user.IUser;

import org.limp.basework.MachiningException;
import org.limp.basework.SimpleBean;
import org.limp.basework.SimpleBean4Table;
import org.limp.basework.SimpleBeanMachining;
import org.limp.basework.Table;
import org.limp.basework.impl.CommonBean4HSQ;
import org.limp.basework.impl.SimpleBean4TableImpl;
import org.limp.basework.tools.BaseworkUtil;
import org.limp.mine.DateTrimmer;
import org.limp.mine.EncryptTool;
import org.limp.mine.RandomUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 贷款申请数据加工
 * 
 * @author mido
 * 
 */
public class LoanApplyMachining implements SimpleBeanMachining {

	private static final Logger LOG = LoggerFactory
			.getLogger(LoanApplyMachining.class);

	@SuppressWarnings( { "unchecked", "rawtypes" })
	public SimpleBean machining(SimpleBean bean, Table table,
			CommonBean4HSQ request, Connection conn, int type)
			throws MachiningException {

		LOG.debug("type={}", type);

		if (type == -4) {
			if (ISystemContext.invalidSesstion(request.getRequest())) {
				throw new MachiningException("invalid session.");
			}
			// 更新会话用户对象信息
			IUser user = ISystemContext.getSessionUser(request.getRequest());
			bean.getResource().put("LA_STATUS", "0");
			bean.getResource().put("LA_DATE", DateTrimmer.getYMDHMS());
			bean.getResource().put("LA_CUSTOMEID", user.id());
			bean.getResource().put("LA_CUSTOMERNAME", user.iname());
		} else if (type == 3) {
			SimpleBean4Table sbt = new SimpleBean4TableImpl("BCXD_INDENT");
			sbt.getResource().put("idid", bean.getResource().get("LA_INDENID"));
			sbt.getResource().put("idapplystatus", "1");
			BaseworkUtil basework = new BaseworkUtil();
			try {
				basework.manualUpdate1(sbt, conn);
			} catch (Exception ex) {
				throw new MachiningException(
						"lock indent for loan-apply error.", ex);
			}
		}
		return null;
	}

}
